<template>
  <div style="background-color: rgb(244,245,247);">
    <!--detailNav组件 顶部导航栏-->
    <div class="biliMainHeader">
      <detailNav :position="false"></detailNav>
    </div>
    <!--头部-->
    <div class="h">
      <div class="wrapper">
        <div class="h-inner">
          <div class="h-gradient"></div>
          <div class="h-user">
            <div class="h-info clearfix">
              <div class="avatar-container">
                <div>
                  <div class="bili-avatar" style="width: 60px;height:60px;">
                    <img class="bili-avatar-img bili-avatar-face bili-avatar-img-radius"
                         alt="" src="">
                    <span class="bili-avatar-icon bili-avatar-right-icon  bili-avatar-size-60"></span>
                  </div>
                </div>
                <a target="_blank" href="#" class="avatar-cover">更换头像</a>
              </div>
              <div class="h-basic">
                <div><span id="h-name">坑萌拐妹</span>
                  <span id="h-ceritification" class="icon"></span>
                  <span id="h-gender" class="icon gender"></span>
                  <a href="//www.bilibili.com/html/help.html#k" target="_blank" class="h-level m-level">
                    <user-level :userlevel="'5'"></user-level>
                  </a>
                  <div class="h-vipType disable">大会员</div>
                  <div class="space-fans-medal"><!---->
                    <div class="normal-medal">
                      <div class="normal-left">
                        <i class="iconfont icon-jiahao" style="font-size: 10px;margin-left: 2px"></i>
                      </div>
                      <div class="normal-right"><p>粉丝勋章</p></div>
                    </div>
                  </div>
                </div>
                <div class="h-basic-spacing">
                  <input id="h-sign" type="text" placeholder="编辑个性签名" maxlength="60" class="space_input">
                </div><!---->
              </div>
            </div>
          </div>
          <div title="更换皮肤" class="space-theme-trigger icon" :style="backgroundPosition" @mouseover="mouseInBackground" @mouseout="mouseOutBackground">
          </div>
          <div class="be-dropdown h-version">
            <div class="h-v-btn popup-select">
              视角：
              <span class="h-version-state">我自己</span>
              <span class="iconfont icon-xiangxia" style="font-size: 10px;margin-left: 5px"></span>
            </div>
          </div><!---->
        </div>
      </div>
    </div>
    <!--导航--->
    <div class="n daohang-sticky">
      <!--导航栏-->
      <div class="n-inner clearfix">
        <!--左-->
        <div class="n-tab-links" @mouseleave="outChange">
          <!--          @mouseover="updateBar(false,0)" @mouseout="changeOffset"-->
          <a ref="tabsList0" href="javascript:;" class="n-btn hover-blue" @mousemove="inUpdateBar(0)"  @click="clickBar(0)">
            <span style="color: #00c091;" class="iconfont icon-shouye"></span>
            <span :class="['n-text','common-margin',{textColor:textColor === 0}]">主页</span>
          </a>
          <a ref="tabsList1" href="javascript:;" class="n-btn hover-blue" @mousemove="inUpdateBar(1)" @click="clickBar(1)">
            <span style="color: #fb7299;" class="iconfont icon-dongtaixuanzhong"></span>
            <span :class="['n-text','common-margin',{textColor:textColor === 1}]">动态</span>
          </a>
          <a ref="tabsList2" href="javascript:;" class="n-btn hover-blue" @mousemove="inUpdateBar(2)"  @click="clickBar(2)">
            <span style="color: #02b5da;" class="iconfont icon-dianshi-F"></span>
            <span :class="['n-text','common-margin',{textColor:textColor === 2}]">投稿</span>
            <span class="n-num common-margin">1</span>
          </a>
          <a ref="tabsList3" href="javascript:;" class="n-btn hover-blue" @mousemove="inUpdateBar(3)"  @click="clickBar(3)">
            <span style="color: #23c9ed;" class="iconfont icon-heji1"></span>
            <span :class="['n-text','common-margin',{textColor:textColor === 3}]">合集和列表</span>
            <span class="n-num common-margin">0</span>
          </a>
          <a ref="tabsList4" href="javascript:;" class="n-btn hover-blue" @mousemove="inUpdateBar(4)" @click="clickBar(4)">
            <span style="color: #f3a034;" class="iconfont icon-shoucang-tianchong"></span>
            <span :class="['n-text','common-margin',{textColor:textColor === 4}]">收藏</span>
            <span class="n-num common-margin">31</span>
          </a>
          <a ref="tabsList5" href="javascript:;" class="n-btn hover-blue" @mousemove="inUpdateBar(5)" @click="clickBar(5)">
            <span style="color: #ff5d47;font-size: 14px" class="iconfont icon-aixin"></span>
            <span :class="['n-text','common-margin',{textColor:textColor === 5}]">订阅</span>
          </a>
          <a ref="tabsList6" href="javascript:;" class="n-btn hover-blue" @mousemove="inUpdateBar(6)" @click="clickBar(6)">
            <span style="color: #23c9ed;" class="iconfont icon-hejishezhi"></span>
            <span :class="['n-text','common-margin',{textColor:textColor === 6}]">设置</span>
          </a>
        </div>
        <!--中-->
        <div class="clearfix g-search search-container">
          <input type="text" placeholder="搜索视频、动态" class="space_input">
          <span class="iconfont icon-sousuo search-btn"></span>
        </div>
        <!--右-->
        <div class="n-statistics">
          <a href="javascript:;" class="n-data hover-blue-p" :class="followTextColor == -1?'follow-text-color':''" title="140" @click="clickFollowBar('-1')">
            <p class="n-data-k">关注数</p>
            <p class="n-data-v">140</p>
          </a>
          <a href="javascript:;" class="n-data hover-blue-p" :class="followTextColor == -5?'follow-text-color':''" title="1" @click="clickFollowBar('-5')">
            <p class="n-data-k">粉丝数</p>
            <p class="n-data-v">1</p>
          </a>
          <div title="截至2023.12.19, 视频、动态、专栏累计获赞4" class="n-data">
            <p class="n-data-k">获赞数</p>
            <p class="n-data-v">4</p>
          </div>
          <div title="截止昨天，播放数总计为0" class="n-data">
            <p class="n-data-k">播放数</p>
            <p class="n-data-v">0</p>
          </div>
        </div>
      </div>
      <!--底部高亮条-->
      <div class="n-cursor" :style="barStyle"></div>
    </div>
    <!--主体-->
    <div class="wrapper clearfix" style="overflow: hidden;border-radius: 4px;min-height: 400px;">
      <!--主页-->
      <initial-page v-if="pageIndex === 0"></initial-page>
      <!--动态-->
      <dynamic-page v-if="pageIndex === 1"></dynamic-page>
      <!--投稿-->
      <contribute-page v-if="pageIndex === 2"></contribute-page>
      <!--合集列表-->
      <compilations-page v-if="pageIndex === 3"></compilations-page>
      <!--收藏-->
      <collection-page v-if="pageIndex === 4"></collection-page>
      <!--订阅-->
      <subscribe-page v-if="pageIndex === 5"></subscribe-page>
      <!--设置-->
      <setting-page v-if="pageIndex === 6"></setting-page>
      <!--关注 followIndexData自定义：规定-1为关注数，-5为粉丝数-->
      <myfollow :followIndexData="followIndexData" v-if="pageIndex === 7"></myfollow>
    </div>
  </div>

</template>

<script>
import detailNav from '@/components/detailComponent/detailNav';
import UserLevel from "@/components/userLevel";
import InitialPage from "@/components/personalHomepageComponent/tabs/initialPage";
import DynamicPage from "@/components/personalHomepageComponent/tabs/dynamicPage";
import ContributePage from "@/components/personalHomepageComponent/tabs/contributePage";
import CompilationsPage from "@/components/personalHomepageComponent/tabs/compilationsPage";
import CollectionPage from "@/components/personalHomepageComponent/tabs/collectionPage";
import SubscribePage from "@/components/personalHomepageComponent/tabs/subscribePage";
import SettingPage from "@/components/personalHomepageComponent/tabs/settingPage";
import Myfollow from "@/components/personalHomepageComponent/fans/myFollow";

export default {
  /**个人主页组件*/
  name: "mainPage",
  components: {
    Myfollow,
    SettingPage,
    SubscribePage,
    CollectionPage,
    CompilationsPage,
    ContributePage,
    DynamicPage,
    InitialPage,
    UserLevel,
    detailNav,
  },
  data() {
    return {
      // 标签默认宽度
      barWidth: 47,
      // 标签偏移量
      barOffset: 20,
      // 标签默认宽度
      barWidthCopy: 47,
      // 标签偏移量
      barOffsetCopy: 20,
      // 标签文本颜色
      textColor:0,
      // 关注粉丝文字颜色
      followTextColor:0,
      // tabs控制
      pageIndex:0,
      // 右上角图片控制
      bgX:0,
      followIndexData:'',
    }
  },
  created() {

  },
  computed: {
    // 动态计算标签默认宽度和偏移量
    barStyle() {
      return {
        width: `${this.barWidth}px`,
        transform: `translate3d(${this.barOffset}px,0px,0px)`
      }
    },
    backgroundPosition(){
      return{
        'background-position':`${this.bgX}px,0px`
      }
    }
  },
  methods: {
    // 单击粉丝数时触发
    clickFollowBar(index){
      this.followTextColor = parseInt(index)
      if (this.pageIndex == 7){
        // 向子组件传值
        this.followIndexData = index
      }else {
        // 显示第7个组件
        this.pageIndex = 7
        // 向子组件传值
        this.followIndexData = index
      }
    },
    mouseInBackground(){
      for (let i = 0; i < 9; i++) {
        setTimeout(() => {
          this.bgX -= 58
          // console.log(this.bgX)
        }, 10*i)
      }
    },
    mouseOutBackground(){
      for (let i = 0; i < 9; i++) {
        setTimeout(() => {
          this.bgX += 58
          // console.log(this.bgX)
        }, 10*i)
      }
    },
    // 移入标签时
    inUpdateBar(index){
      this.updateBar(index)
    },
    // 移出父div时回到点击标签的位置
    outChange(){
      this.barWidth = this.barWidthCopy
      this.barOffset = this.barOffsetCopy
    },
    // 点击标签时
    clickBar(index){
      this.followTextColor = 0
      this.updateBar(index)
      // 保存点击值
      this.barWidthCopy = this.barWidth
      this.barOffsetCopy = this.barOffset
      this.textColor = index
      // 切换tabs页面
      this.pageIndex = index
    },
    // 改变标签默认宽度和偏移量
    updateBar(index = 0) {
      this.$nextTick(()=>{
        // 设置宽度
        if (eval('this.$refs.tabsList'+index) === undefined) return
        this.barWidth = eval('this.$refs.tabsList'+index).offsetWidth
        // 设置偏移量
        if (index > 0){
          let offset = 20
          for (let i = 0; i < index; i++) {
            if (eval('this.$refs.tabsList'+i) === undefined) return
            offset += (eval('this.$refs.tabsList'+i).offsetWidth + 31)
          }
          this.barOffset = offset
        }else {
          this.barOffset = 20
        }
      })
    }
  },
}
</script>

<style scoped>
/*选中时字体颜色*/
.textColor {
  color: #00a1d6;
}
.follow-text-color p{
  color: #00a1d6;
}
.hover-blue-p:hover p{
  color: #00a1d6;
}
.biliMainHeader {
  height: 64px;
}
.daohang-sticky{
  box-shadow: 0 0 0 1px #eee;
  border-radius: 0 0 8px 8px;
  position:sticky;
  top:0;
  margin: 0 auto 10px auto;width: 1283px;z-index: 10;
}
.h {
  position: relative;
  z-index: 2;
}

.wrapper {
  width: 1283px !important;
}

.wrapper {
  /*border: 1px solid #eee;*/
  margin: 0 auto;
  position: relative;
}

.h-inner {
  background-image: url('/src/assets/img/h-inner.png');
  background-position: 50%;
  background-size: cover;
  transition: background-image .2s ease, background-size 1s ease;
  padding-top: 116px;
  position: relative;
}

.h .h-gradient {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 84px;
  background-image: url();
  background-repeat: repeat-x;
}

.h .h-user {
  position: relative;
  z-index: 1;
}

.h .h-info {
  margin-left: 20px;
  padding-bottom: 16px;
  display: -ms-flexbox;
  display: flex;
  -ms-flex-align: center;
  align-items: center;
}

.clearfix {
  zoom: 1;
}

.avatar-container {
  position: relative;
}

.bili-avatar {
  display: block;
  position: relative;
  /*头像无法加载时的站位图片*/
  background-image: url();
  -webkit-background-size: cover;
  background-size: cover;
  border-radius: 50%;
  margin: 0;
  padding: 0;
}

.bili-avatar-img {
  border: 2px solid hsla(0, 0%, 100%, .4);
}

.bili-avatar-img-radius {
  border-radius: 50%;
}

.bili-avatar-img {
  border: none;
  display: block;
  -o-object-fit: cover;
  object-fit: cover;
}

.bili-avatar-face {
  position: absolute;
  top: 50%;
  left: 50%;
  -webkit-transform: translate(-50%, -50%);
  -moz-transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  -o-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  width: 100%;
  height: 100%;
}

.bili-avatar .bili-avatar-size-60 {
  width: 18px;
  height: 18px;
  bottom: -1px;
}

.avatar-cover {
  position: absolute;
  top: 0;
  left: 0;
  width: 60px;
  height: 60px;
  background: rgba(0, 0, 0, .6);
  font-size: 12px;
  color: #fff;
  line-height: 60px;
  text-align: center;
  opacity: 0;
  border-radius: 50%;
  transition: opacity .2s;
}

.h .avatar-container:hover .avatar-cover {
  opacity: 1;
}

.h #h-sign:hover {
  background: hsla(0, 0%, 100%, .2);
  box-shadow: 0 0 0 1px hsla(0, 0%, 100%, .5);
}

.h #h-sign:focus {
  background: #fff;
  box-shadow: inset 0 2px 4px rgba(35, 54, 86, .3);
  color: #6d757a;
}

.h .h-basic {
  color: #fff;
  font-size: 0;
  margin-left: 22px;
}

.h #h-name {
  display: inline-block;
  margin-right: 5px;
  font-weight: 700;
  line-height: 18px;
  font-size: 18px;
  vertical-align: middle;
}

.h #h-ceritification {
  background-position: -217px -792px;
  display: none;
  width: 11px;
  height: 18px;
  margin: 0 1px 0 6px;
  vertical-align: middle;
}

.h .gender {
  display: none;
  width: 21px;
  height: 18px;
  margin-right: 5px;
  vertical-align: middle;
  background-position: -212px -922px;
}

.h .h-vipType.disable {
  margin-left: 5px;
}

.h .h-vipType {
  background-color: #ccd0d7;
  color: #99a2aa;
  display: inline-block;
  height: 16px;
  line-height: 16px;
  border-radius: 4px;
  font-size: 12px;
  /*color: #fff;*/
  padding: 0 5px;
  /*background-color: #f45a8d;*/
  vertical-align: middle;
  margin-right: 5px;
  cursor: pointer;
}

.h .space-fans-medal {
  display: inline-block;
  vertical-align: middle;
  margin-left: 5px;
}

.normal-medal {
  height: 16px;
  display: flex;
  cursor: pointer;
}

.normal-left {
  width: 16px;
  height: 100%;
  background: #e5e9ef;
  border: 1px dashed #99a2aa;
  box-sizing: border-box;
  border-radius: 1px;
  position: relative;
}

.normal-right {
  width: 48px;
  height: 100%;
  position: relative;
  background: #000;
  opacity: .7;
  border-radius: 1px;
}

.normal-right p {
  width: 200%;
  height: 200%;
  font-size: 20px;
  transform: scale(.5);
  transform-origin: top left;
  line-height: 32px;
  color: #fff;
  position: absolute;
  top: 0;
  left: 0;
  text-align: center;
}

.h .h-basic .h-basic-spacing {
  margin-top: 6px;
}

.h #h-sign {
  background: transparent;
  border-radius: 4px;
  border: none;
  box-shadow: none;
  color: hsla(0, 0%, 100%, .8);
  font-size: 12px;
  font-family: Microsoft Yahei;
  line-height: 26px;
  height: 26px;
  margin-left: -5px;
  padding: 0 5px;
  position: relative;
  top: -1px;
  width: 730px;
}

.h .space-theme-trigger {
  background-image: url('/src/assets/img/theme-trigger-new.png');
  /*background-position: 58px 0;*/
  border-radius: 0 4px 0 0;
  cursor: pointer;
  width: 58px;
  height: 49px;
  transition: opacity .2s ease;
  position: absolute;
  top: 0;
  right: 0;
}

.icon {
  vertical-align: middle;
  background-repeat: no-repeat;
}
.h .h-version {
  position: absolute;
  top: 15px;
  right: 57px;
}
.be-dropdown {
  position: relative;
  display: inline-block;
  cursor: pointer;
}
.h .h-v-btn {
  background: rgba(0, 0, 0, .45);
  border-radius: 4px;
  color: #fff;
  cursor: pointer;
  font-size: 12px;
  line-height: 30px;
  transition: all .1s ease;
  padding: 0 10px;
}

.n .n-inner {
  height: 66px;
  background: #fff;
  /*box-shadow: 0 0 0 1px #eee;*/
  /*border-radius: 0 0 4px 4px;*/
  padding: 0 20px;
}
.clearfix {
  display: block;
}
.n .n-tab-links {
  display: inline-block;
  font-size: 0;

  vertical-align: middle;
}
.n .n-btn {
  display: inline-block;
  font-size: 0;
  height: 66px;
  line-height: 66px;
  position: relative;
  margin-right: 31px;
  /*margin-bottom: -3px;*/
}
.n .n-text {
  font-size: 13px;
}
.n .n-num {
  margin-left: 2px;
  font-size: 12px;
  color: #99a2aa;
  font-family: Arial;
}

.common-margin{
  margin-left: 5px;
}
.g-search {
  position: relative;
  display: inline-block;
  width: 134px;
  height: 30px;
  vertical-align: middle;
}
.g-search input {
  position: absolute;
  height: 30px;
  width: 134px;
  padding: 0 29px 0 10px;
  line-height: 30px;
  color: #222;
  font-size: 12px;
  border: 1px solid #ccd0d7;
  border-radius: 15px;
  box-shadow: none;
  box-sizing: border-box;
}
.space_input {
  line-height: 28px;
  height: 28px;
  padding: 0 10px;
  transition: all .3s ease;
  vertical-align: top;
  border: 1px solid #ccd0d7;
  border-radius: 0;
}
.space_input:focus {
  border-color: #00a1d6;
}
.g-search .search-btn {
  position: absolute;
  right: 8px;
  top: 3px;
  /*background-position: -1111px -81px;*/
  color: #e3e5e7;
  cursor: pointer;
}
.search-btn:hover{
  color: #00a1d6;
}
.n .n-statistics {
  float: right;
  height: 66px;
}
.n .n-data {
  display: flex;
  flex-direction: column;
  justify-content: center;
  float: left;
  height: 66px;
  padding: 10px 5px;
  text-align: center;
  box-sizing: border-box;
}
.n-data-k {
  line-height: 14px;
  font-size: 12px;
  color: #99a2aa;
}
.n-data-v {
  line-height: 16px;
  margin-top: 5px;
  color: #222;
  font-size: 12px;
}
.n .n-cursor {
  background: #00a1d6;
  height: 3px;
  transition: all .2s ease;
  position: absolute;
  bottom: -1px;
  left: 0;
  border-radius: 1px;
}
</style>
